package com.topisv.tms.utils.jd;

import java.io.IOException;

import com.jd.open.api.sdk.JdClient;
import com.jd.open.api.sdk.JdException;
import com.jd.open.api.sdk.request.delivery.DeliveryLogisticsGetRequest;
import com.jd.open.api.sdk.request.order.OrderGetRequest;
import com.jd.open.api.sdk.request.order.OrderLbpPrintDataGetRequest;
import com.jd.open.api.sdk.request.order.OrderPrintDataGetRequest;
import com.jd.open.api.sdk.request.order.OrderPrintRequest;
import com.jd.open.api.sdk.request.order.OrderSearchRequest;
import com.jd.open.api.sdk.request.order.OrderSopOutstorageRequest;
import com.jd.open.api.sdk.request.order.OrderSopPrintDataGetRequest;
import com.jd.open.api.sdk.request.order.OrderSopWaybillUpdateRequest;
import com.jd.open.api.sdk.request.order.OrderSoplPrintDataGetRequest;
import com.jd.open.api.sdk.request.ware.WareSkuGetRequest;
import com.jd.open.api.sdk.response.delivery.DeliveryLogisticsGetResponse;
import com.jd.open.api.sdk.response.order.OrderGetResponse;
import com.jd.open.api.sdk.response.order.OrderLbpPrintDataGetResponse;
import com.jd.open.api.sdk.response.order.OrderPrintDataGetResponse;
import com.jd.open.api.sdk.response.order.OrderPrintResponse;
import com.jd.open.api.sdk.response.order.OrderSearchResponse;
import com.jd.open.api.sdk.response.order.OrderSopOutstorageResponse;
import com.jd.open.api.sdk.response.order.OrderSopPrintDataGetResponse;
import com.jd.open.api.sdk.response.order.OrderSopWaybillUpdateResponse;
import com.jd.open.api.sdk.response.order.OrderSoplPrintDataGetResponse;
import com.jd.open.api.sdk.response.ware.WareSkuGetResponse;

public abstract class JdUtils {

	public static WareSkuGetResponse getSku(JdClient client,String sku)throws JdException{
		WareSkuGetRequest request=new WareSkuGetRequest();
		request.setSkuId(sku);
		WareSkuGetResponse response=client.execute(request);
		return response;
	}

	/**
	 * 查询订单
	 * @param client
	 * @param startDate 起始时间
	 * @param endDate   终止时间
	 * @param page      页数
	 * @param orderStatus  订单状态
	 * @return
	 * @throws JdException
	 */
	public static OrderSearchResponse queryOrdeno(JdClient client,String startDate,String endDate,String page,String orderStatus) throws JdException {
		OrderSearchRequest request = new OrderSearchRequest();
		request.setStartDate(startDate);
		request.setEndDate(endDate);
		request.setPage(page);
		request.setPageSize("100");
		request.setOrderState(orderStatus);
		OrderSearchResponse response = client.execute(request);
		return response;

	}

	/**
	 * 根据订单号查询面单打印数据
	 * @param client
	 * @param ordeno
	 * @return
	 * @throws JdException
	 */
	public static OrderPrintDataGetResponse getPrintData(JdClient client,String ordeno) throws JdException {
		OrderPrintDataGetRequest request = new OrderPrintDataGetRequest();
		request.setOrderId(ordeno);
		OrderPrintDataGetResponse response = client.execute(request);
		return response;
	}

	/**
	 * SOPL获取面单打印数据
	 * 
	 * @param client
	 * @throws JdException
	 */
	public static OrderSoplPrintDataGetResponse getSOPLPrint(JdClient client, String orderId)
			throws JdException {
		OrderSoplPrintDataGetRequest request = new OrderSoplPrintDataGetRequest();
		request.setOrderId(orderId);
		OrderSoplPrintDataGetResponse response = client.execute(request);
		return response;

	}

	/**
	 * LBP获取面单打印数据
	 * 
	 * @param client
	 * @throws JdException
	 */
	public static OrderLbpPrintDataGetResponse getLBPPrint(JdClient client, String orderId)
			throws JdException {
		OrderLbpPrintDataGetRequest request = new OrderLbpPrintDataGetRequest();
		request.setOrderId(orderId);
		OrderLbpPrintDataGetResponse response = client.execute(request);
		return response;

	}

     /**
      * 根据订单号获取SOP面单打印数据
      * @param client
      * @param ordeno
      * @return
      * @throws JdException
      */
	public static OrderSopPrintDataGetResponse getSOPPrint(JdClient client,String ordeno) throws JdException {
		OrderSopPrintDataGetRequest request = new OrderSopPrintDataGetRequest();
		request.setOrderId(ordeno);
		OrderSopPrintDataGetResponse response = client.execute(request);
		return response;
	}

	/**
	 * 根据订单号获取面单信息
	 * @param client
	 * @param ordeno
	 * @return
	 * @throws JdException
	 */
	public static OrderPrintResponse getPrint(JdClient client,String ordeno) throws JdException {
		OrderPrintRequest request = new OrderPrintRequest();
		request.setOrderId(ordeno);
		OrderPrintResponse response = client.execute(request);
		return response;
	}

	/**
	 * 根据订单号与订单状态获得订单信息
	 * @param client
	 * @param ordeno
	 * @param orderStatus
	 * @return
	 * @throws JdException
	 */
	public static OrderGetResponse getOrder(JdClient client,String ordeno,String orderStatus) throws JdException {

		OrderGetRequest request = new OrderGetRequest();
		request.setOrderId(ordeno);
		request.setOrderState(orderStatus);
		OrderGetResponse response = client.execute(request);
		return response;
	}

	/**
	 * SOP更新运单号
	 * @param client
	 * @param ordeno
	 * @param logisticsId
	 * @param waybillNo
	 * @param tradeNO
	 * @return
	 * @throws JdException
	 */
	public static OrderSopWaybillUpdateResponse updateSOPOrdenoWaybillNo(JdClient client, String ordeno,String logisticsId,String waybillNo,String tradeNO)
			throws JdException {
		OrderSopWaybillUpdateRequest request = new OrderSopWaybillUpdateRequest();
		request.setOrderId(ordeno);
		request.setLogisticsId(logisticsId);
		request.setWaybill(waybillNo);
		request.setTradeNo(tradeNO);
		OrderSopWaybillUpdateResponse response = client.execute(request);
		return response;
	}

	/**
	 * 订单出库
	 * @param client
	 * @param ordeno
	 * @param logisticsId
	 * @param waybillNo
	 * @param tradeNO
	 * @return
	 * @throws JdException
	 */
	public static OrderSopOutstorageResponse outSopOrdeno(JdClient client, String ordeno,String logisticsId,String waybillNo,String tradeNO)
			throws JdException {
		OrderSopOutstorageRequest request = new OrderSopOutstorageRequest();
		request.setOrderId(ordeno);
		request.setLogisticsId(logisticsId);
		request.setWaybill(waybillNo);
		request.setTradeNo(tradeNO);
		OrderSopOutstorageResponse response = client.execute(request);
		return response;
	}

	/**
	 * 商家获取物流公司信息
	 * 
	 * @param client
	 * @throws JdException
	 * @throws IOException
	 */
	public static DeliveryLogisticsGetResponse getLogistics(JdClient client) throws JdException,
			IOException {
		DeliveryLogisticsGetRequest request = new DeliveryLogisticsGetRequest();
		DeliveryLogisticsGetResponse response = client.execute(request);
		return response;
	}

}
